package staffSize;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import partition.CityPartitioner;

import java.io.IOException;

/**
 * Date:2024/12/14
 * @author Isabella
 */
public class StaffSizeDriver {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration con = new Configuration();

        Job job = Job.getInstance(con);

        job.setJarByClass(StaffSizeDriver.class);

        job.setMapperClass(StaffSizeMapper.class);
        job.setReducerClass(StaffSizeReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //参考<=Partitioner里面的字典数+1（多出来一个放其它不在字典里面的）
        job.setNumReduceTasks(8);
        job.setPartitionerClass(CityPartitioner.class);

        Path inputP = new Path("input/jobData.csv");
        Path outputP = new Path("output/StaffSize");

        FileInputFormat.addInputPath(job,inputP);
        FileOutputFormat.setOutputPath(job,outputP);

        FileSystem fs = FileSystem.get(con);
        if ( fs.exists(outputP) ){
            fs.delete(outputP,true);
        }

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
